package com.atguigu.dwm.model.mapper;

import com.atguigu.dwm.model.bean.DmDimension;
import com.atguigu.dwm.plan.bean.DpBusiProcess;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 维度 Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-03
 */
@Mapper
@DS("dwm")
public interface DmDimensionMapper extends BaseMapper<DmDimension> {

//    @Select("select  t.*,dw.model_name  from dm_dimension t \n" +
//            "   left join dp_data_warehouse_model  dw on t.model_id=dw.id\n" +
//            "where t.is_deleted='0'  ${condition}")
//    List<DmDimension> selectQueryList(String condition);


    @Select("select t.id ,name_chn ,name_eng,t.last_update_time, dw.model_name   ,dim_sub.table_names from\n" +
            "     dm_dimension t\n" +
            "    left join dp_data_warehouse_model dw on t.model_id = dw.id\n" +
            "     left join  (       select  id as dim_id,group_concat(table_name ) table_names\n" +
            "     from\n" +
            "     (\n" +
            "         select ddm.id,table_name  from  dm_dimension ddm\n" +
            "        join\n" +
            "        (\n" +
            "         select dim_id  as dim_ids,table_name from dm_table where dim_id is not null and stat_dim_ids<>''\n" +
            "         union all\n" +
            "         select stat_dim_ids as dim_ids,table_name from dm_table where stat_dim_ids is not null and stat_dim_ids<>''\n" +
            "         ) dt on  find_in_set(ddm.id, dim_ids )\n" +
            "     )dm_grp  group by id\n" +
            "     ) dim_sub on dim_sub.dim_id =t.id" +
            " where t.is_deleted='0'  ${condition}")
    List<DmDimension> selectQueryList(String condition);

    @Select("select  count(*)  from dm_dimension t \n" +
            "where t.is_deleted='0'  ${condition}")
    Integer selectQueryCount(String condition);

}
